import {React,useState,useEffect} from 'react';
import { Breadcrumb, Col, Row ,Form,Input,Table, Button} from 'antd'
import { Link } from 'react-router-dom';
import FormItem from 'antd/lib/form/FormItem';
import axios from 'axios';

const BingChuangXinXi = (props) => {
    console.log(props);
    const [bingRenXingMing,setbingRenXingMing]=useState("巩羽凡")
    const [bingRenXingBie,setbingRenXingBie]=useState("男")
    const [BingRenNianLing,setBingRenNianLing]=useState(23)
    const [zhuZhiYiSheng,setzhuZhiYiSheng]=useState("袁州")
    const [KeShi,setKeShi]=useState("骨科")
    const [bingChuangHao,setbingChuangHao]=useState("001")

    const [changqiData,setchangqiData]=useState([
        {
            key:1,
            kaiShiShiJian:"2021-01-12",
            jieShuShiJian:"2021-03-18",
            yiShengMing:"杨森",
            yaoPinMing:"矿泉水",
            yaoPinYongLiang:"1升",
            yaoPinYongFa:"一日三次",
            yongYaoShiJian:"饭后",
            yaoPinGuiGe:"一瓶5升"
        }
    ])
    const [duanqiData,setduanqiData]=useState([
        {
            key:1,
            kaiShiShiJian:"2021-01-12",
            jieShuShiJian:"2021-03-18",
            yiShengMing:"杨森",
            yaoPinMing:"矿泉水",
            yaoPinYongLiang:"1升",
            yaoPinYongFa:"一日三次",
            yongYaoShiJian:"饭后",
            yaoPinGuiGe:"一瓶5升"
        }
    ])
    const colums=[
        {
            key:"kaiShiShiJian",
            title:"开始时间",
            dataIndex:"kaiShiShiJian",
            align:"center"
        },
        {
            key:"jieShuShiJian",
            title:"结束时间",
            dataIndex:"jieShuShiJian",
            align:"center"
        },
        {
            key:"yaoPinMing",
            title:"药品名称",
            dataIndex:"yaoPinMing",
            align:"center"
        },
        {
            key:"yaoPinYongLiang",
            title:"药品用量",
            dataIndex:"yaoPinYongLiang",
            align:"center"
        },
        {
            key:"yaoPinYongFa",
            title:"药品用法",
            dataIndex:"yaoPinYongFa",
            align:"center"
        },
        {
            key:"yongYaoShiJian",
            title:"用药时间",
            dataIndex:"yongYaoShiJian",
            align:"center"
        },
        {
            key:"yaoPinGuiGe",
            title:"药品规格",
            dataIndex:"yaoPinGuiGe",
            align:"center"
        },
        
    ]
    const duanqi=[
        {
            key:"yiZhuRiQi",
            title:"医嘱日期",
            dataIndex:"yiZhuRiQi",
            align:"center"
        },
        {
            key:"yaoPinMing",
            title:"药品名称",
            dataIndex:"yaoPinMing",
            align:"center"
        },
        {
            key:"yaoPinYongLiang",
            title:"药品用量",
            dataIndex:"yaoPinYongLiang",
            align:"center"
        },
        {
            key:"yaoPinYongFa",
            title:"药品用法",
            dataIndex:"yaoPinYongFa",
            align:"center"
        },
        {
            key:"jianGeShiJian",
            title:"间隔时间",
            dataIndex:"jianGeShiJian",
            align:"center"
        },
        {
            key:"yaoPinGuiGe",
            title:"药品规格",
            dataIndex:"yaoPinGuiGe",
            align:"center"
        },
    ]
    const goback=()=>{
        props.history.push("/zy/bfxx")
    }
    // 获取当前病人长期医嘱
    const getCQYiZhu=()=>{
        // console.log(props.location.state);
        axios("/changQiYiZhuDengJi/chaXunByZhuYuanHao",{
            method:"GET",
            params:{zhuYuanHao:props.location.state}
        })
        .then(res=>{
            // console.log(res);
            if(res.data.code===200){
                let temp=res.data.data
                let arr=[]
                for(let i=0;i<temp.length;i++){
                    let tempObj={}
                    tempObj.key=i+1
                    tempObj.kaiShiShiJian=temp[i].kaiShiShiJian
                    tempObj.jieShuShiJian=temp[i].tingZhiShiJian
                    tempObj.yaoPinMing=temp[i].yaoPinMingCheng
                    tempObj.yaoPinYongLiang=temp[i].yaoPinYongLiang
                    tempObj.yaoPinYongFa=temp[i].yaoPinYongFa
                    tempObj.yongYaoShiJian=temp[i].yongYaoShiJian
                    tempObj.yaoPinGuiGe=temp[i].yaoPinGuiGe
                    arr.push(tempObj)
                }
                setchangqiData(arr)
            }
        })
    }
    // 获取当前病人临时医嘱
    const getLSYiZhu=()=>{
        axios("/linShiYiZhuDengJiBiao/chaXunByZhuYuanHao",{
            method:"GET",
            params:{zhuYuanHao:props.location.state}
        })
        .then(res=>{
            // console.log(res);
            if(res.data.code===200){
                let temp=res.data.data
                let arr=[]
                for(let i=0;i<temp.length;i++){
                    let tempObj={}
                    tempObj.key=i+1
                    tempObj.yiZhuRiQi=temp[i].yiZhuRiQi
                    tempObj.yaoPinMing=temp[i].yaoPinMingCheng
                    tempObj.yaoPinYongLiang=temp[i].yaoPinYongLiang
                    tempObj.yaoPinYongFa=temp[i].yaoPinYongFa
                    tempObj.jianGeShiJian=temp[i].jianGeShiJian
                    tempObj.yaoPinGuiGe=temp[i].yaoPinGuiGe
                    arr.push(tempObj)
                }
                setduanqiData(arr)
            }
        })
    }
    // 获取当前病人信息
    const getBingRenXinXi=()=>{
        axios("/chuangWeiDengJi/chaXunByZhuYuanHao",{
            method:"GET",
            params:{zhuYuanHao:props.location.state}
        })
        .then(res=>{
            console.log(res);
            if(res.data.code===200){
                let temp=res.data.data
                setbingRenXingMing(temp[0].ruYuanBingRenJiBenZiLiaoDengJi.xingMing)
                setbingRenXingBie(temp[0].ruYuanBingRenJiBenZiLiaoDengJi.xingBie=="1"?"男":"女")
                setBingRenNianLing(temp[0].ruYuanBingRenJiBenZiLiaoDengJi.chuShengRiQi)
                setzhuZhiYiSheng(temp[0].ruYuanBingRenJiBenZiLiaoDengJi.zhuZhi)
                setKeShi(temp[0].ruYuanBingRenJiBenZiLiaoDengJi.keBie)
                setbingChuangHao(temp[0].chuangHao)
            }
        })
    }
    useEffect(()=>{
        getCQYiZhu()
        getLSYiZhu()
        getBingRenXinXi()
    },[])
    return (
        <div>
            {/* 面包屑导航 */}
            <Row>
                <Col>
                    <Breadcrumb style={{ marginBottom: 24 }}>
                        <Breadcrumb.Item>病房管理</Breadcrumb.Item>
                        <Breadcrumb.Item>
                            <Link to={{ pathname: "/zy/bfxx" }}>病房信息</Link>
                        </Breadcrumb.Item>
                        <Breadcrumb.Item>病床信息</Breadcrumb.Item>
                    </Breadcrumb>
                </Col>
            </Row>
            {/* 基本信息标签 */}
            <Row>
                <Col span={24} style={{height:"30px",display:"flex"}}>
                    <div style={{height:"100%",width:"10px",backgroundColor:"rgb(31, 109, 226)"}}></div>
                    <div style={{height:"100%",lineHeight:"30px",marginLeft:"20px"}}><h1 style={{fontWeight:700}}>病人基本信息</h1></div>
                </Col>
            </Row>
            {/* 病人基本信息 */}
            <Row style={{marginTop:"20px"}}>
                <Col span={24}>
                    <Form layout="inline">
                        <FormItem label="姓名">
                            <Input disabled value={bingRenXingMing}></Input>
                        </FormItem>
                        <FormItem label="性别">
                            <Input disabled style={{width:"100px"}} value={bingRenXingBie}></Input>
                        </FormItem>
                        <FormItem label="出生日期">
                            <Input disabled value={BingRenNianLing}></Input>
                        </FormItem>
                        <FormItem label="主治医生">
                            <Input disabled value={zhuZhiYiSheng}></Input>
                        </FormItem>
                        <FormItem label="科室">
                            <Input disabled value={KeShi}></Input>
                        </FormItem>
                        <FormItem label="病床号">
                            <Input disabled value={bingChuangHao}></Input>
                        </FormItem>
                    </Form>
                </Col>
            </Row>
            {/* 长期医嘱标签 */}
            <Row style={{marginTop:"20px"}}>
                <Col span={24} style={{height:"30px",display:"flex"}}>
                    <div style={{height:"100%",width:"10px",backgroundColor:"rgb(31, 109, 226)"}}></div>
                    <div style={{height:"100%",lineHeight:"30px",marginLeft:"20px"}}><h1 style={{fontWeight:700}}>长期医嘱</h1></div>
                </Col>
            </Row>
            {/* 长期医嘱 */}
            <Row style={{marginTop:"20px"}}>
                <Col span={24}>
                    <Table columns={colums} dataSource={changqiData} pagination={false}></Table>
                </Col>
            </Row>
            {/* 短期医嘱标签 */}
            <Row style={{marginTop:"20px"}}>
                <Col span={24} style={{height:"30px",display:"flex"}}>
                    <div style={{height:"100%",width:"10px",backgroundColor:"rgb(31, 109, 226)"}}></div>
                    <div style={{height:"100%",lineHeight:"30px",marginLeft:"20px"}}><h1 style={{fontWeight:700}}>短期医嘱</h1></div>
                </Col>
            </Row>
            {/* 短期医嘱 */}
            <Row style={{marginTop:"20px"}}>
                <Col span={24}>
                    <Table columns={duanqi} dataSource={duanqiData} pagination={false}></Table>
                </Col>
            </Row>
            {/* 返回按钮 */}
            <Row>
                <Col span={24} style={{textAlign:"center",marginTop:"20px"}}>
                <Button type="primary" onClick={goback}>返回</Button>
                </Col>
            </Row>
        </div>
    );
}

export default BingChuangXinXi;
